package model;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;

public class Student extends BaseModel {
	private Integer id;
	private String sName;
	private Integer sex;
	private String sYear;
	private Integer collegeId;
	private Integer majorId;
	private String classNo;
	private String company;
	private String city;
	private String sPost;
	private BigDecimal wages;
	private Integer companyType;
	private String cName;
	private String uName;

	private Integer pageNo;
	private Integer rowCount;

	public String getuName() {
		return uName;
	}

	public void setuName(String uName) {
		this.uName = uName;
	}

	public String getcName() {
		return cName;
	}

	public void setcName(String cName) {
		this.cName = cName;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getRowCount() {
		return rowCount;
	}

	public void setRowCount(Integer rowCount) {
		this.rowCount = rowCount;
	}

	public Student() {

	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getsName() {
		return sName;
	}

	public void setsName(String sName) {
		this.sName = sName;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public String getsYear() {
		return sYear;
	}

	public void setsYear(String sYear) {
		this.sYear = sYear;
	}

	public Integer getCollegeId() {
		return collegeId;
	}

	public void setCollegeId(Integer collegeId) {
		this.collegeId = collegeId;
	}

	public Integer getMajorId() {
		return majorId;
	}

	public void setMajorId(Integer majorId) {
		this.majorId = majorId;
	}

	public String getClassNo() {
		return classNo;
	}

	public void setClassNo(String classNo) {
		this.classNo = classNo;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getsPost() {
		return sPost;
	}

	public void setsPost(String sPost) {
		this.sPost = sPost;
	}

	public BigDecimal getWages() {
		return wages;
	}

	public void setWages(BigDecimal wages) {
		this.wages = wages;
	}

	public Integer getCompanyType() {
		return companyType;
	}

	public void setCompanyType(Integer companyType) {
		this.companyType = companyType;
	}

	public void getParams(HttpServletRequest req) {
		this.id = getIValueINM(req.getParameter("id"));
		this.uName = getValueINM(req.getParameter("uName"));
		this.sName = getValueINM(req.getParameter("sName"));
		this.sex = getIValueINM(req.getParameter("sex"));
		this.sYear = getValueINM(req.getParameter("sYear"));
		this.collegeId = getIValueINM(req.getParameter("collegeId"));
		this.majorId = getIValueINM(req.getParameter("majorId"));
		this.classNo = getValueINM(req.getParameter("classNo"));
		this.company = getValueINM(req.getParameter("company"));
		this.city = getValueINM(req.getParameter("city"));
		this.sPost = getValueINM(req.getParameter("sPost"));
		this.wages = getDValueINM(req.getParameter("wages"));
		this.companyType = getIValueINM(req.getParameter("companyType"));
		this.cName = getValueINM(req.getParameter("cName"));

		this.pageNo = setPageNo(req.getParameter("pageNo"));// 第几页
		this.rowCount = dealRowCount(req.getParameter("rowCount"));// 单页行数
	}

	public String getInsertSql() {

		StringBuffer values = new StringBuffer();

		StringBuffer sql = new StringBuffer("insert into stu_info(");

		if (uName != null) {
			sql.append("u_name,");
			values.append("'").append(uName).append("',");
		}
		if (sex != null) {
			sql.append("sex,");
			values.append(sex + ",");
		}
		if (sYear != null) {
			sql.append("s_year,");
			values.append("'").append(sYear).append("',");
		}
		if (collegeId != null) {
			sql.append("college_id,");
			values.append(collegeId + ",");
		}
		if (majorId != null) {
			sql.append("major_id,");
			values.append(majorId + ",");
		}
		if (classNo != null) {
			sql.append("class_no,");
			values.append("'").append(classNo).append("',");
		}
		if (company != null) {
			sql.append("company,");
			values.append("'").append(company).append("',");
		}
		if (companyType != null) {
			sql.append("company_type,");
			values.append(companyType + ",");
		}
		if (city != null) {
			sql.append("city,");
			values.append("'").append(city).append("',");
		}
		if (sPost != null) {
			sql.append("s_post,");
			values.append("'").append(sPost).append("',");
		}
		if (wages != null) {
			sql.append("wages,");
			values.append(wages + ",");
		}

		sql.deleteCharAt(sql.length() - 1);

		values.deleteCharAt(values.length() - 1);

		sql.append(")values(").append(values).append(")");

		return sql.toString();
	}

	public String getSelectSql() {
		StringBuffer sql = new StringBuffer("SELECT s.*, c.s_name, m.c_name FROM stu_info as s ");
		sql.append(" left join sch_info as c on s.college_id = c.college_id");
		sql.append("  left join cla_info as m on s.major_id = m.major_id where 1=1");
		if (id != null) {
			sql.append(" and s.id = ").append(id);
		}
		if (uName != null) {
			sql.append(" and s.u_name = '").append(uName).append("'");
		}
		if (sYear != null) {
			sql.append(" and s.s_year = '").append(sYear).append("'");
		}
		if (collegeId != null) {
			sql.append(" and s.college_id = ").append(collegeId);
		}
		if (majorId != null) {
			sql.append(" and s.major_id = ").append(majorId);
		}

		return sql.toString();
	}

	public String updateSql() {
		StringBuffer values = new StringBuffer();
		StringBuffer sql = new StringBuffer("update stu_info");
		if (uName != null) {
			values.append("u_name = '").append(uName).append("',");
		}
		if (sex != null) {
			values.append("sex = '").append(sex).append("',");
		}
		if (sYear != null) {
			values.append("s_year = '").append(sYear).append("',");
		}
		if (collegeId != null) {
			values.append("college_id = '").append(collegeId).append("',");
		}
		if (majorId != null) {
			values.append("major_id = '").append(majorId).append("',");
		}
		if (classNo != null) {
			values.append("class_no = '").append(classNo).append("',");
		}
		if (company != null) {
			values.append("company = '").append(company).append("',");
		}
		if (companyType != null) {
			values.append("company_type = '").append(companyType).append("',");
		}
		if (city != null) {
			values.append("city = '").append(city).append("',");
		}
		if (sPost != null) {
			values.append("s_post = '").append(sPost).append("',");
		}
		if (wages != null) {
			values.append("wages = '").append(wages).append("',");
		}
		if (values.length() > 0) {
			values.deleteCharAt(values.length() - 1);
			sql.append(" set ").append(values).append(" where id = ").append(id);
			return sql.toString();
		} else {
			return null;
		}
	}

	public String getTotalCountSql() {
		StringBuffer sql = new StringBuffer("SELECT count(*) FROM stu_info where 1=1 ");
		if (uName != null) {
			sql.append(" and u_name = '").append(uName).append("'");
		}
		if (sYear != null) {
			sql.append(" and s_year = '").append(sYear).append("'");
		}
		if (collegeId != null) {
			sql.append(" and college_id = ").append(collegeId);
		}
		if (majorId != null) {
			sql.append(" and major_id = ").append(majorId);
		}

		return sql.toString();
	}

	public static void main(String[] args) {

	}
}
